package com.ruoyi.business.webapi.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mysqldump.vo.BizProjectBackupVo;
import com.ruoyi.mysqldump.service.IBizProjectBackupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 备份管理Controller
 *
 * @author Tellsea
 * @date 2022-02-11
 */
@Api(value = "备份管理控制器", tags = {"备份管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mysqldump/projectBackup")
public class BizProjectBackupController extends BaseController {

    private final IBizProjectBackupService iBizProjectBackupService;

    @ApiOperation("查询备份管理列表")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:list')")
    @GetMapping("/list")
        public TableDataInfo<BizProjectBackupVo> list(BizProjectBackupVo entity) {
        return iBizProjectBackupService.queryList(entity);
    }

    @ApiOperation("导出备份管理列表")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:export')")
    @Log(title = "备份管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<BizProjectBackupVo> export(@Validated BizProjectBackupVo entity) {
        List<BizProjectBackupVo> list = iBizProjectBackupService.queryList(entity).getRows();
        ExcelUtil<BizProjectBackupVo> util = new ExcelUtil<BizProjectBackupVo>(BizProjectBackupVo.class);
        return util.exportExcel(list, "备份管理");
    }

    @ApiOperation("获取备份管理详细信息")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:query')")
    @GetMapping("/getInfo/{id}")
    public AjaxResult<BizProjectBackupVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable("id") Long id) {
        return AjaxResult.success(iBizProjectBackupService.queryById(id));
    }

    @ApiOperation("新增备份管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:add')")
    @Log(title = "备份管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping("add")
    public AjaxResult<Void> add(@Validated @RequestBody BizProjectBackupVo entity) {
        return toAjax(iBizProjectBackupService.save(entity) ? 1 : 0);
    }

    @ApiOperation("修改备份管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:edit')")
    @Log(title = "备份管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("edit")
    public AjaxResult<Void> edit(@Validated @RequestBody BizProjectBackupVo entity) {
        return toAjax(iBizProjectBackupService.updateById(entity) ? 1 : 0);
    }

    @ApiOperation("删除备份管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectBackup:remove')")
    @Log(title = "备份管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                   @PathVariable Long[] ids) {
        return toAjax(iBizProjectBackupService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
